﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif 

// **********************************************************************
// Copyright (C) XM
// Author: 赵思佳
// Date: 2019-01-17
// Desc: 编辑器脚本
// **********************************************************************
namespace SpaceDFramework
{
    public class MsgDispactherEditor:MonoBehaviourSimplify
    {
#if UNITY_EDITOR
///编辑器脚本
		[MenuItem("SpaceD/消息机制", false, 7)]
		static void CallMenu(){
            ///菜单逻辑
            //MsgDispacther<string>.Register("消息1", OnMsgReceived);
            //MsgDispacther<string>.Send("消息1","Hello world");
            //MsgDispacther<string>.UnRegister("消息1", OnMsgReceived);
            UnityEditor.EditorApplication.isPlaying = true;
            GameObject temp= new GameObject();
            temp.AddComponent<MsgDispactherEditor>();
        }
#endif
        private void Awake()
        {
            RegisterMsg("Do", DoSomething);
        }

        private void DoSomething(string msg)
        {
            CommonUtil.LogFormat("消息1:{0}", msg);
        }

        private IEnumerator Start() {
            MsgDispacther<string>.Send("Do","Hello");
            yield return new WaitForSeconds(1);
            MsgDispacther<string>.Send("Do", "Hello1");
        }
        //static void OnMsgReceived(string msg) {
        //    CommonUtil.LogFormat("消息1:{0}", msg);
        //}

        public override void OnBeforeDestory()
        {
            
        }

    }
}
